package com.lyeducation.services.video;

import com.lyeducation.core.base.TokenConstants;
import com.lyeducation.core.video.VideoTypeService;
import com.lyeducation.entities.course.VideoTypeEntity;
import com.lyeducation.repository.VideoTypeRepository;
import com.lyeducation.util.controllerUtil.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class VideoTypeServiceImpl implements VideoTypeService {
    @Autowired
    private VideoTypeRepository videoTypeRepository;

    @Override
    public JsonResult getAllVideoType() {
        return JsonResult.putSuccess(videoTypeRepository.findAll());
    }

    @Override
    public JsonResult addVideoType(String type) {
        VideoTypeEntity videoTypeEntity = new VideoTypeEntity();
        videoTypeEntity.setId(TokenConstants.generateUserId());
        videoTypeEntity.setType(type);
        return JsonResult.putSuccess(videoTypeRepository.save(videoTypeEntity));
    }

    @Override
    public JsonResult delVideoType(String type) {
        if (videoTypeRepository.deleteByType(type) == 1)
            return JsonResult.putSuccess();
        return JsonResult.putFail("删除视频类型失败");
    }
}
